<template>
  <el-dialog
     v-drag
    :title="!dataForm.configId ? '新增' : '修改'"
    :close-on-click-modal="false"
    :visible.sync="visible">
    <el-form :model="dataForm" :inline="true" :rules="dataRule" ref="dataForm" @keyup.enter.native="dataFormSubmit()" label-width="80px">
    <el-form-item label="" prop="configId">
      <el-input size="mini"  v-model="dataForm.configId" placeholder="" clearable></el-input>
    </el-form-item>
                                                                                                                                                                </el-form>
    <span slot="footer" class="dialog-footer">
      <el-button size="mini" @click="visible = false">取消</el-button>
      <el-button size="mini" type="primary" @click="dataFormSubmit()">确定</el-button>
    </span>
  </el-dialog>
</template>

<script>
  export default {
    data () {
      return {
        visible: false,
        dataForm: {
          configId: 0,
          storeId: '',
          storeCode: '',
          storeLicense: '',
          storeAuthStatus: '',
          storeSa: '',
          storeIp: '',
          storeMac: '',
          storeHost: '',
          socialPort: '',
          socialComm: '',
          storeAppkey: '',
          storeApiSecret: '',
          storeApiId: '',
          clickProductDownload: '',
          clickPurchaseDownload: '',
          clickAdjustPriceDownload: '',
          migrateMemberStatus: '',
          migrateStockStatus: '',
          migratePurchaseStatus: '',
          migrateSaleStatus: '',
          migratePriceStatus: '',
          codeRelationErrorPath: '',
          initErrorPath: '',
          syncErrorPath: '',
          sellErrorPath: '',
          onlineErrorPath: '',
          socialUploadType: '',
          socialStartDate: '',
          queryPayCount: '',
          paySleepTime: '',
          socialAutoType: '',
          changeShiftTime: '',
          downloadRebateTimes: '',
          downloadRebateDate: '',
          createTime: '',
          updateTime: '',
          status: '',
          isDeleted: '',
          remark: ''
        },
        dataRule: {
          storeId: [
            { required: true, message: '不能为空', trigger: 'blur' }
          ],
          storeCode: [
            { required: true, message: '不能为空', trigger: 'blur' }
          ],
          storeLicense: [
            { required: true, message: '不能为空', trigger: 'blur' }
          ],
          storeAuthStatus: [
            { required: true, message: '门店认证状态不能为空', trigger: 'blur' }
          ],
          storeSa: [
            { required: true, message: '不能为空', trigger: 'blur' }
          ],
          storeIp: [
            { required: true, message: '门店IP不能为空', trigger: 'blur' }
          ],
          storeMac: [
            { required: true, message: '门店物理地址不能为空', trigger: 'blur' }
          ],
          storeHost: [
            { required: true, message: '门店主机名称不能为空', trigger: 'blur' }
          ],
          socialPort: [
            { required: true, message: '社保接口端口不能为空', trigger: 'blur' }
          ],
          socialComm: [
            { required: true, message: '社保接口com连接不能为空', trigger: 'blur' }
          ],
          storeAppkey: [
            { required: true, message: '云支付 医药管理系统密钥不能为空', trigger: 'blur' }
          ],
          storeApiSecret: [
            { required: true, message: '云支付 医药管理系统密匙不能为空', trigger: 'blur' }
          ],
          storeApiId: [
            { required: true, message: '云支付 医药管理系统编号不能为空', trigger: 'blur' }
          ],
          clickProductDownload: [
            { required: true, message: '判断是否点击下载商品资料不能为空', trigger: 'blur' }
          ],
          clickPurchaseDownload: [
            { required: true, message: '判断是否点击下载出库资料不能为空', trigger: 'blur' }
          ],
          clickAdjustPriceDownload: [
            { required: true, message: '判断是否点击下载调价单不能为空', trigger: 'blur' }
          ],
          migrateMemberStatus: [
            { required: true, message: '迁移会员状态不能为空', trigger: 'blur' }
          ],
          migrateStockStatus: [
            { required: true, message: '迁移会员状态不能为空', trigger: 'blur' }
          ],
          migratePurchaseStatus: [
            { required: true, message: '迁移验收状态不能为空', trigger: 'blur' }
          ],
          migrateSaleStatus: [
            { required: true, message: '迁移销售出库状态不能为空', trigger: 'blur' }
          ],
          migratePriceStatus: [
            { required: true, message: '迁移价格状态不能为空', trigger: 'blur' }
          ],
          codeRelationErrorPath: [
            { required: true, message: '不能为空', trigger: 'blur' }
          ],
          initErrorPath: [
            { required: true, message: '不能为空', trigger: 'blur' }
          ],
          syncErrorPath: [
            { required: true, message: '不能为空', trigger: 'blur' }
          ],
          sellErrorPath: [
            { required: true, message: '不能为空', trigger: 'blur' }
          ],
          onlineErrorPath: [
            { required: true, message: '不能为空', trigger: 'blur' }
          ],
          socialUploadType: [
            { required: true, message: '不能为空', trigger: 'blur' }
          ],
          socialStartDate: [
            { required: true, message: '不能为空', trigger: 'blur' }
          ],
          queryPayCount: [
            { required: true, message: '不能为空', trigger: 'blur' }
          ],
          paySleepTime: [
            { required: true, message: '支付间隔时间不能为空', trigger: 'blur' }
          ],
          socialAutoType: [
            { required: true, message: '社保是否自动上传 1:自动不能为空', trigger: 'blur' }
          ],
          changeShiftTime: [
            { required: true, message: '最近交班时间不能为空', trigger: 'blur' }
          ],
          downloadRebateTimes: [
            { required: true, message: '返利下载次数不能为空', trigger: 'blur' }
          ],
          downloadRebateDate: [
            { required: true, message: '返利下载日期不能为空', trigger: 'blur' }
          ],
          createTime: [
            { required: true, message: '创建时间不能为空', trigger: 'blur' }
          ],
          updateTime: [
            { required: true, message: '修改时间不能为空', trigger: 'blur' }
          ],
          status: [
            { required: true, message: '是否可用 1:是不能为空', trigger: 'blur' }
          ],
          isDeleted: [
            { required: true, message: '是否删除 1:是不能为空', trigger: 'blur' }
          ],
          remark: [
            { required: true, message: '备注不能为空', trigger: 'blur' }
          ]
        }
      }
    },
    methods: {
      init (id) {
        this.dataForm.configId = id || 0
        this.visible = true
        this.$nextTick(async () => {
          this.$refs['dataForm'].resetFields()
          if (this.dataForm.configId) {
            const res = await this.$http({
              url: `/base/basestoreconfig/info/${this.dataForm.configId}`,
              method: 'get',
              params: this.$http.adornParams()
            })
                let data = res.data
                if (data && data.code === 0) {
                    this.dataForm = data.baseStoreConfig
                }
          }
        })
      },
      // 表单提交
      dataFormSubmit () {
        this.$refs['dataForm'].validate(async (valid) => {
          if (valid) {
            const res = await this.$http({
              url:`/base/basestoreconfig/${!this.dataForm.configId ? 'save' : 'update'}`,
              method: 'post',
             data: this.$http.adornData( this.dataForm)
            })
            let data = res.data
            if (data && data.code === 0) {
                this.$message({
                        message: '操作成功',
                        type: 'success',
                        duration: 1500,
                        onClose: () => {
                    this.visible = false
                    this.$emit('refreshDataList')
                }
            })
            } else {
                this.$message.error(data.msg)
            }
          }
        })
      }
    }
  }
</script>
